/*
 * Split.h
 */

#ifndef SPLIT_H_
#define SPLIT_H_
#include <iostream>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cstring>

class split {
public:
	string request;
	string ip;
	string timestamp;
	string type;
	string filename;
	char *cstr, *p;
public:
	string getFiletype() {
		string nt = filename;
		cout << "filename is" << filename;
		char *str;
		str = new char[nt.size() + 1];
		strcpy(str, nt.c_str());
		char *p;
		p = strchr(str, '/');
		if (p != NULL) {
			return "FULL";
		} else {

			return "PART";
		}
	}
	void setRequest(string req) {
		timestamp = "";
		request = req;
		cstr = new char[request.size() + 1];
		strcpy(cstr, request.c_str());
		p = strtok(cstr, " ");
		int i = 0;
		while (p != NULL) {
			switch (i) {
			case 0:
				ip = p;
				break;
			case 1:
				timestamp = timestamp + " " + p;
				break;
			case 2:
				type = p;
				break;
			case 3:
				filename = p;
				break;
			case 4:
				break;
			}
			if(i==3)
				break;
			p = strtok(NULL, " ");
			string type = p;
			if (i == 0)
				i++;
			if (i == 1 && (type != "GET" || type != "PUT"))
				i--;
			if (type == "GET" || type == "PUT")
				i++;
			i++;
		}
	}
	string getIp() {
		return ip;

	}
	string getTimestamp() {
		return timestamp;
	}
	string getType() {
		return type;
	}
	string getFilename() {
		return filename;
	}
};

#endif /* SPLIT_H_ */
